<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="GB2312"/>

<xsl:variable name="viewPath"></xsl:variable>
<xsl:variable name="userName"></xsl:variable> 

<xsl:template match="viewentries">
	<viewentries>
	<xsl:attribute name="toplevelentries">
		<xsl:value-of select="@toplevelentries"/>
	</xsl:attribute>
	<xsl:apply-templates select="viewentry">
		<xsl:sort select="./entrydata/textlist/text[starts-with(text(),concat($userName,'#'))]" order = "descending"  />
		<xsl:sort select="./entrydata/text[starts-with(text(),concat($userName,'#'))]" order = "descending"  />
	</xsl:apply-templates>
	</viewentries>
</xsl:template>

<xsl:template match="viewentry">
	<viewentry>
		<xsl:attribute name="viewPath">
			<xsl:value-of select="$viewPath"/>
		</xsl:attribute> 
		<xsl:apply-templates select="@*|node()"/>
	</viewentry>
</xsl:template>

<xsl:template match = "@*|node()" > 
	<xsl:copy> 
		<xsl:apply-templates select = "@*|node()" /> 
	</xsl:copy>
</xsl:template> 

 <xsl:template match="textlist">	
	<xsl:apply-templates select="text" mode="attriveTime"/>
  </xsl:template>

  <xsl:template match="text">
	<xsl:if test="starts-with(text(),concat($userName,'#'))">
		<text>
			<xsl:value-of select="substring-after(.,'#')"/>
		</text>
	</xsl:if>
	<xsl:if test="not(starts-with(text(),concat($userName,'#')))">
		<text>
			<xsl:value-of select="."/>
		</text>
	</xsl:if>
  </xsl:template>

  <xsl:template match="text" mode="attriveTime">
	<xsl:if test="starts-with(text(),concat($userName,'#'))">
		<text>
			<xsl:value-of select="substring-after(.,'#')"/>
		</text>
	</xsl:if>
  </xsl:template>

</xsl:stylesheet>
